import {Component, OnInit} from '@angular/core';
import {ListMemCollectComponent} from '../list-mem-collect.component';
import {MemCollectCondition} from '../../mem-collect.type';
import * as fa from '@fortawesome/free-solid-svg-icons';
import {Services} from '../../../../../frame/module/services';
import {isNullOrUndefined} from 'util';
import {UrlRou} from '../../../../../frame';
import {Zero3Confirm} from '../../../../../frame/global/zero3-confirm/zero3-confirm.component';

@Component({
    selector: 'app-func-list-mem-collect',
    templateUrl: './func-list-mem-collect.component.html',
    styleUrls: ['./func-list-mem-collect.component.css']
})
export class FuncListMemCollectComponent implements OnInit {

    list = {
        icon: fa.faSearch,
        nickname: '查',
        click: (event) => {
            let page = 0;
            let size = 15;
            if (isNullOrUndefined(this.listMemCollect.table) || isNullOrUndefined(this.listMemCollect.table.data)
                || isNullOrUndefined(this.listMemCollect.table.data.page) || isNullOrUndefined(this.listMemCollect.table.data.page.size)) {
            } else {
                page = this.listMemCollect.table.data.page.number;
                size = this.listMemCollect.table.data.page.size;
            }
            Services.memCollect.list(this.listMemCollect.search.condition, {
                page: page,
                size: size,
                // orders: 'createTime-desc,serNum-asc'
                orders: this.listMemCollect.table.head.orderBy()
            }).subscribe(item => {
                this.listMemCollect.table.data = item;
            });
        }
    };

    reList = {
        icon: fa.faUndo,
        nickname: '重置',
        click: (event) => {
            this.listMemCollect.search.condition = new MemCollectCondition();
            Services.memCollect.list(this.listMemCollect.search.condition, {
                page: 0,
                size: 15,
                orders: 'createTime-desc,serNum-asc'
            }).subscribe(item => {
                this.listMemCollect.table.data = item;
            });
        }
    };

    add = {
        icon: fa.faPlus,
        nickname: '增',
        click: (event) => {
            this.listMemCollect.router.navigate([UrlRou.memCollect.add, {
                moduleId: this.listMemCollect.module.id, menuId: this.listMemCollect.module.menu.id
            }]);
            console.log('fun add');
        }
    };

    delete = {
        icon: fa.faTrashAlt,
        nickname: '删',
        click: async (event) => {
            console.log('fun delete');
            const result = await Zero3Confirm.req('确定要删除？');
            if (result === true) {
                const condition = new MemCollectCondition();
                condition.uuidList = [];
                const uuidMap = this.listMemCollect.table.body.tr.selectedUuid;
                uuidMap.forEach((value, key, map) => {
                    condition.uuidList.push(key);
                });
                Services.memCollect.delete(condition, this.delete.callback).subscribe();
                console.log('do delete');
            } else {
                console.log('no delete');
            }
        },
        callback: {
            success: (result) => {
                this.list.click(null);
                // this.listMemCollect.router.navigate([UrlRou.memCollect.list]);
                console.log('success');
            },
            error: (result) => {
                // this.errRes.error = result.error;
                // this.errRes.statusText = result.statusText;
                console.log(result);
                console.log('error');
            }
        }
    };

    modify = {
        icon: fa.faPen,
        nickname: '改',
        click: (event) => {
            const condition = new MemCollectCondition();
            condition.uuidList = [];
            const uuidMap = this.listMemCollect.table.body.tr.selectedUuid;
            uuidMap.forEach((value, key, map) => {
                condition.uuidList.push(key);
            });
            Services.memCollect.modify(condition, this.listMemCollect.module);
            console.log('fun modify');
        }
    };

    audit = {
        icon: fa.faCheckDouble,
        nickname: '审',
        submit: {
            icon: fa.faCheck,
            nickname: '提交',
            click: async (event) => {
                console.log('fun submit');
                const result = await Zero3Confirm.req('确定要提交吗？');
                if (result === true) {
                    const condition = new MemCollectCondition();
                    condition.uuidList = [];
                    const uuidMap = this.listMemCollect.table.body.tr.selectedUuid;
                    uuidMap.forEach((value, key, map) => {
                        condition.uuidList.push(key);
                    });
                    Services.memCollect.audit.submit(condition, this.audit.submit.callback).subscribe();
                    console.log('do delete');
                } else {
                    console.log('no delete');
                }
            },
            callback: {
                success: (result) => {
                    this.list.click(null);
                    // this.listMemCollect.router.navigate([UrlRou.memCollect.list]);
                    console.log('success');
                },
                error: (result) => {
                    // this.errRes.error = result.error;
                    // this.errRes.statusText = result.statusText;
                    console.log(result);
                    console.log('error');
                }
            }
        },
        audit: {
            icon: fa.faCheckCircle,
            nickname: '通过',
            click: async (event) => {
                console.log('fun audit');
                const result = await Zero3Confirm.req('确定要审批通过吗？');
                if (result === true) {
                    const condition = new MemCollectCondition();
                    condition.uuidList = [];
                    const uuidMap = this.listMemCollect.table.body.tr.selectedUuid;
                    uuidMap.forEach((value, key, map) => {
                        condition.uuidList.push(key);
                    });
                    Services.memCollect.audit.audit(condition, this.audit.submit.callback).subscribe();
                    console.log('do delete');
                } else {
                    console.log('no delete');
                }
            },
            callback: {
                success: (result) => {
                    this.list.click(null);
                    // this.listMemCollect.router.navigate([UrlRou.memCollect.list]);
                    console.log('success');
                },
                error: (result) => {
                    // this.errRes.error = result.error;
                    // this.errRes.statusText = result.statusText;
                    console.log(result);
                    console.log('error');
                }
            }
        },
        reject: {
            icon: fa.faCheckSquare,
            nickname: '驳回',
            click: async (event) => {
                console.log('fun reject');
                const result = await Zero3Confirm.req('确定要驳回吗？');
                if (result === true) {
                    const condition = new MemCollectCondition();
                    condition.uuidList = [];
                    const uuidMap = this.listMemCollect.table.body.tr.selectedUuid;
                    uuidMap.forEach((value, key, map) => {
                        condition.uuidList.push(key);
                    });
                    Services.memCollect.audit.reject(condition, this.audit.submit.callback).subscribe();
                    console.log('do delete');
                } else {
                    console.log('no delete');
                }
            },
            callback: {
                success: (result) => {
                    this.list.click(null);
                    // this.listMemCollect.router.navigate([UrlRou.memCollect.list]);
                    console.log('success');
                },
                error: (result) => {
                    // this.errRes.error = result.error;
                    // this.errRes.statusText = result.statusText;
                    console.log(result);
                    console.log('error');
                }
            }
        },
    };

    data = {
        icon: fa.faDatabase,
        nickname: '数',
        export: {
            icon: fa.faFileExport,
            nickname: '导出',
            click: (event) => {
                console.log('fun export');
            },
        },
        import: {
            icon: fa.faFileImport,
            nickname: '导入',
            click: (event) => {
                console.log('fun import');
            },
        },
    };


    report = {
        icon: fa.faChartBar,
        nickname: '报',
        chartLine: {
            icon: fa.faChartLine,
            nickname: 'Line',
            click: (event) => {
                this.listMemCollect.router.navigate([UrlRou.memCollect.report, {
                    moduleId: this.listMemCollect.module.id,
                    menuId: this.listMemCollect.module.menu.id
                }]);
                console.log('fun chartLine');
            },
        },
        chartArea: {
            icon: fa.faChartArea,
            nickname: 'Area',
            click: (event) => {
                this.listMemCollect.router.navigate([UrlRou.memCollect.report, {
                    moduleId: this.listMemCollect.module.id,
                    menuId: this.listMemCollect.module.menu.id
                }]);
                console.log('fun chartArea');
            },
        },
        chartPie: {
            icon: fa.faChartPie,
            nickname: 'Pie',
            click: (event) => {
                this.listMemCollect.router.navigate([UrlRou.memCollect.report, {
                    moduleId: this.listMemCollect.module.id,
                    menuId: this.listMemCollect.module.menu.id
                }]);
                console.log('fun chartPie');
            },
        },
    };

    help = {
        icon: fa.faQuestionCircle,
        nickname: '帮助',
        click: (event) => {
            console.log('fun report');
        },
    };

    constructor(public listMemCollect: ListMemCollectComponent) {
        this.listMemCollect.func = this;
    }

    ngOnInit() {
    }

}
